package com.lagou.edu.mvcframework.security;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class PermissionException extends RuntimeException {
    private List<String> required;

    public PermissionException(List<String> required) {
        this.required = required;
    }

    public String getMessage() {
        return String.format("权限不足，需要权限[%s]", required);
    }

    public void render(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String message = String.format("权限不足，需要权限[%s]", required);
        request.setAttribute("message", message);
        request.getRequestDispatcher("/WEB-INF/views/error/permissionErr.jsp").forward(request, response);
    }
}
